package be.dch.gui.panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextArea;

import be.dch.gui.GarminMapGuiWindow;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

public final class Srtm2OsmPanel extends AbstractPanel implements ActionListener {

    /** * */
    private static final long serialVersionUID = 2509863425053526666L;

    private static Srtm2OsmPanel instance = new Srtm2OsmPanel();
    private static final String CMD_OPTION = "option";

    private static final String COLUMN_SPECS = "1dlu:grow,50dlu,3dlu,150dlu,3dlu,50dlu,3dlu,50dlu,1dlu:grow";
    private static final String ROW_SPECS = "pref,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref:grow";

    private final transient JTextArea txtArea;

    private Srtm2OsmPanel() {
	super();

	final FormLayout layout = new FormLayout(Srtm2OsmPanel.COLUMN_SPECS, Srtm2OsmPanel.ROW_SPECS);

	final CellConstraints constraints = new CellConstraints();

	final PanelBuilder builder = new PanelBuilder(layout);

	final JButton btnOption = new JButton("Options");
	btnOption.setActionCommand(Srtm2OsmPanel.CMD_OPTION);
	btnOption.addActionListener(this);
	builder.add(btnOption, constraints.rchw(3, 8, 1, 1));

	final JLabel lblOutput = new JLabel("Output:");
	builder.add(lblOutput, constraints.rchw(7, 2, 1, 1));

	this.txtArea = new JTextArea();
	lblOutput.setLabelFor(this.txtArea);
	builder.add(this.txtArea, constraints.rchw(7, 4, 9, 5));

	this.add(builder.getPanel());
    }

    public static Srtm2OsmPanel getInstance() {
	return Srtm2OsmPanel.instance;
    }

    public void actionPerformed(final ActionEvent event) {
	if (event.getActionCommand().equalsIgnoreCase(Srtm2OsmPanel.CMD_OPTION)) {
	    GarminMapGuiWindow.getInstance().selectTab(OptionPanel.getInstance());
	    OptionPanel.getInstance().selectTab(Srtm2OsmOptionPanel.getInstance());
	}

    }

    @Override
    public String getPanelTitle() {
	return "Srtm";
    }

    @Override
    public Icon getPanelIcon() {
	return this.createImageIcon("/images/file-nasa-icon.jpg", "Nasa");
    }

    public JTextArea getTxtArea() {
	return this.txtArea;
    }
}
